
#include "PublisherInfo.h"

using namespace std;
using namespace ttg::services;

//---------------------
//--- PublisherInfo ---
//---------------------

PublisherInfo::PublisherInfo(const char *name)
	:NamedObject(name)
{
	//nothing
}

void PublisherInfo::addSubscriber(Subscriber *ss, void (*d)(Subscriber *ss, Event *ev))
{
	infos.push_back(new SubscriberInfo(ss, d));
}

void PublisherInfo::removeSubscriber(Subscriber *ss)
{
	throw Error(Error::FATAL, "PublisherInfo", "removeSubscriber", "Not implemented yet");
}

void PublisherInfo::sendEvent(Event *ev)
{
	list<SubscriberInfo *>::iterator it = infos.begin();
	while (it != infos.end())
	{
		if (*it != NULL)
			(*it)->sendEvent(ev);
		it++;
	}
}

PublisherInfo::~PublisherInfo()
{
	list<SubscriberInfo *>::iterator it1 = infos.begin();
	//Releasing subscriber infos.
	while (it1 != infos.end())
	{
		SAFE_DELETE(*it1);
		it1++;
	}
}
